#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>

struct st_args{
    int no;         //线程编号
    char name[51];  // 线程名
};

void *thmain1(void *arg); // 线程1的主函数


int main(int argc, char *argv[])
{
    pthread_t thid = 0;

    struct st_args *stargs = new struct st_args;
    stargs->no = 15;
    strcpy(stargs->name, "测试线程");


    if (pthread_create(&thid, NULL, thmain1, stargs) != 0)
    {
        printf("pthread_create failed.\n");
        exit(-1);
    }

    // 等待子线程退出。
    printf("join...\n");
    pthread_join(thid, NULL);
    printf("join ok.\n");
}

void *thmain1(void *arg)
{
    struct st_args *pst = (struct  st_args*)arg;
    printf("no=%d, name=%s\n", pst->no, pst->name);
    delete pst;                          // 释放内存的代码放在线程的主函数中
    printf("线程开始运行。\n");
}